package com.mzw.huaxiarealestatebackend.common.utils;

import lombok.Data;

import java.io.Serializable;

@Data
public class DataResult implements Serializable {
    private Object data;
    private Integer code;
    private String message;

    public DataResult(Integer code, String message, Object data) {
        this.data = data;
        this.code = code;
        this.message = message;
    }
    public DataResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static DataResult ok(String msg){
        return new DataResult(200,msg);
    }

    public static DataResult ok(Object data){
        return new DataResult(200,"SUCCESS",data);
    }

    public static DataResult failure(String msg){
        return new DataResult(403,msg);
    }

    public static DataResult failure(){
        return new DataResult(403,"FAILURE");
    }

    public static DataResult ok(){
        return new DataResult(200,null);
    }

    public static DataResult update(int count){
        String msg = count > 0 ? "SUCCESS" :"FAILURE";
        int code = count > 0 ? 200 : 500;
        return new DataResult(code,msg);
    }

    public static DataResult delete(int count){
        String msg = count > 0 ? "SUCCESS" :"FAILURE";
        int code = count > 0 ? 200 : 500;
        return new DataResult(code,msg);
    }
}
